﻿using System;
using System.Configuration;
using System.Linq;
using System.Web.Script.Services;
using System.Web.Services;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.ServiceModel;
using BookClubIt.Processor;
using DTO = BookClubIt.DTO;


namespace BookClubIt
{
    /// <summary>
    /// Summary description for AjaxFunctions
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class AjaxFunctions : WebService
    {

        [WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public void ChangeBook(int BookClub_Id, int Book_Id, int User_Id)
        {
           
            // update database to set the new asin as the current book for the book club with the id = bid
            BookClubProcessorInstance.ChangeBookInClubById(BookClub_Id, Book_Id);
            BookClubProcessorInstance.AddClubActivity(BookClub_Id, User_Id, "CHANGEBOOK", Book_Id);

          // return bookASIN;
        }

        [WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public void RemoveBookFromShelf(int BookClub_Id, int Book_Id, int User_Id)
        {

            // update database to set the new asin as the current book for the book club with the id = bid
            BookClubProcessorInstance.RemoveBookFromClubShelf(BookClub_Id, Book_Id);
            BookClubProcessorInstance.AddClubActivity(BookClub_Id, User_Id, "REMOVEBOOK", Book_Id);
            
            // return bookASIN;
        }

        [WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string AddBookToShelf(string bookASIN, string BookClub_Id)
        {

            return "done";
        }

        [WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string CreateTopic(string BookClub_Id, string Topic_Title)
        {

            return Topic_Title;
        }

        [WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string SaveBook(string ASIN, int cid)
        {
            DTO.Books books = AmazonProcessorInstance.GetBookByASIN(ASIN);
        //  BookProcessorInstance.SaveBook(book);

            return "t";
        }

    }
}
